package com.example.mcdonaldapplication.info

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.mcdonaldapplication.R

class IndentDetailAdapter(private val indentDetailList: ArrayList<IndentDetailInfo>) : RecyclerView.Adapter<IndentDetailAdapter.ViewHolder>() {
    class ViewHolder(view: View): RecyclerView.ViewHolder(view){
        val tvIndentName: TextView = view.findViewById(R.id.tvIndentName)
        val tvIndentNum: TextView = view.findViewById(R.id.tvIndentNum)
        val tvIndentPrice: TextView = view.findViewById(R.id.tvIndentPrice)
        val ivIndentImg: ImageView = view.findViewById(R.id.ivIndentImg)

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.activity_indent_detail_rv,parent,false)

        return ViewHolder(view)
    }
    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        //绑定数据
        val indentDetailInfo = indentDetailList[position]
        holder.tvIndentName.text = "${indentDetailInfo.name}" //名称

        var num = indentDetailInfo.num
        holder.tvIndentNum.text = "${num}份"//数量

        holder.tvIndentPrice.text = "￥${indentDetailInfo.price}"//价格
        if (indentDetailInfo.img == "0"){
            holder.ivIndentImg.setImageResource(R.drawable.hamburger0)
        } else if (indentDetailInfo.img == "1"){
            holder.ivIndentImg.setImageResource(R.drawable.hamburger1)
        }

    }

    override fun getItemCount(): Int {
        return indentDetailList.size
    }
}